//
//  cameraORphotoalbum.m
//  wanmi
//
//  Created by 翔爷 on 2018/9/13.
//  Copyright © 2018年 翔爷. All rights reserved.
//

#import "cameraORphotoalbum.h"

@interface cameraORphotoalbum ()
@property (nonatomic,strong) UIView *allview;
@property (nonatomic,strong) UIButton *backGroundView;
@property (nonatomic,strong) UIButton *camerabtn;
@property (nonatomic,strong) UIButton *photoalbumbtn;
@property (nonatomic,strong) UIButton *savaButton;
@property (nonatomic,strong) UIButton *cancelbtn;
@end

@implementation cameraORphotoalbum

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        [self.backGroundView addSubview:self.allview];
        
        self.camerabtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        [self.camerabtn setTitle:@"拍照" forState:0];
        [self.camerabtn setTitleColor:[UIColor blackColor] forState:0];
        self.camerabtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [self.camerabtn addTarget:self action:@selector(didSelectButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.allview addSubview:self.camerabtn];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, 1)];
        line.backgroundColor = [UIColor lightGrayColor];
        [_allview addSubview:line];
        
        self.photoalbumbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, 50)];
        [self.photoalbumbtn setTitle:@"相册" forState:0];
        [self.photoalbumbtn setTitleColor:[UIColor blackColor] forState:0];
        self.photoalbumbtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [self.photoalbumbtn addTarget:self action:@selector(didSelectButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.allview addSubview:self.photoalbumbtn];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 101, SCREEN_WIDTH, 1)];
        line2.backgroundColor = [UIColor lightGrayColor];
        [_allview addSubview:line2];
        
//        self.savaButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 101, SCREEN_WIDTH, 50)];
//        [self.savaButton setTitle:localStr(@"save") forState:0];
//        [self.savaButton setTitleColor:[UIColor blackColor] forState:0];
//        self.savaButton.titleLabel.font = [UIFont systemFontOfSize:18];
//        [self.savaButton addTarget:self action:@selector(didSelectButton:) forControlEvents:UIControlEventTouchUpInside];
//        [self.allview addSubview:self.savaButton];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(0, 101, SCREEN_WIDTH, 6)];
        line3.backgroundColor = [UIColor lightGrayColor];
        [_allview addSubview:line3];
        
        
        self.cancelbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 107, SCREEN_WIDTH, 55)];
        [self.cancelbtn setTitle:@"取消" forState:0];
        [self.cancelbtn setTitleColor:[UIColor blackColor] forState:0];
        self.cancelbtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [ self.cancelbtn addTarget:self action:@selector(remove) forControlEvents:UIControlEventTouchUpInside];
        [self.allview addSubview:self.cancelbtn];
        
        
    }
    return self;
}

-(void)showview{
    [[UIApplication sharedApplication].keyWindow.rootViewController.view.window addSubview:self.backGroundView];
    [UIView animateWithDuration:0.2 animations:^{
        self.allview.frame = CGRectMake(0, SCREEN_HEIGHT - 157 - kBottomSafeArea, SCREEN_WIDTH, 157 + kBottomSafeArea);
    }];
}

-(void)didSelectButton:(UIButton *)sender{
    [_delegate cameraORphotoalbumDelegatedidSelectButton:sender];
    [self remove];
}

-(void)remove{
    [UIView animateWithDuration:0.1 animations:^{
        self.allview.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 207 + kBottomSafeArea);
    }completion:^(BOOL finished) {
        [self.backGroundView removeFromSuperview];
    }];
}

-(UIView *)allview {
    if (!_allview) {
        _allview = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT,SCREEN_WIDTH, 207 + kBottomSafeArea)];
        _allview.backgroundColor = [UIColor whiteColor];
        UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_allview.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(8, 8)];
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = path.CGPath;
        _allview.layer.mask = shapeLayer;
    }
    return _allview;
}
-(UIButton *)backGroundView{
    if (!_backGroundView) {
        _backGroundView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT)];
        _backGroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        [_backGroundView addTarget:self action:@selector(remove) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backGroundView;
}
@end
